package com.yx.front.controller;


import com.yx.front.config.global.CommonResult;
import com.yx.front.manager.FriendRelationManager;
import com.yx.front.model.param.AuditRelationParam;
import com.yx.front.model.param.FriendRelationParam;
import com.yx.front.model.vo.FriendRelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 朋友关系表 前端控制器
 * </p>
 *
 * @author YangXiong
 * @since 2023-04-06
 */
@Slf4j
@RestController
@Api(tags = "朋友关系接口")
@RequestMapping("/friend-relation")
public class FriendRelationController {
    @Resource
    private FriendRelationManager friendRelationManager;

    @PostMapping("/add")
    @ApiOperation("添加好友请求")
    public CommonResult<String> add(@RequestBody FriendRelationParam param) {
        log.info("FriendRelationController info add FriendRelationParam={}", param);
        Boolean result = friendRelationManager.add(param);
        if (result) {
            return CommonResult.success("已发送请求，待对方同意");
        }
        return CommonResult.fail("添加失败，请稍后重试");
    }

    @PostMapping("/agree")
    @ApiOperation("同意好友申请")
    public CommonResult<String> agreeApply(@RequestBody AuditRelationParam param) {
        log.info("FriendRelationController info agreeApply AuditRelationParam={}", param);
        Boolean result = friendRelationManager.agreeApply(param);
        if (result) {
            return CommonResult.success("添加成功，快去找他（她）聊天吧");
        }
        return CommonResult.fail("添加失败，请稍后重试");
    }
    @GetMapping("/get/friends")
    @ApiOperation("获取好友列表")
    public CommonResult<List<FriendRelationVo>> getFriends(){
        return friendRelationManager.getFriends();
    }

}

